﻿using bzxxxt.admin.service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace bzxxxt.admin.ashx
{
    /// <summary>
    /// ui_backup_restore 的摘要说明
    /// </summary>
    public class ui_backup_restore : rm_base
    {
        Utils utils = new Utils();
        public override void getall(HttpContext context)
        {
            string where = context.Request.Params["where"] ?? "1=1";
            
            context.Response.Write(utils.getBackupFileList());
        }

        public override void other(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request.Params["action"];
            switch (action)
            {
                case "backup":
                    {
                        string path = context.Server.MapPath("~/db");
                        utils.backup();
                        context.Response.Write(JsonUtil.ToJson(new { success = true, msg = "备份数据库操作成功！" }));
                        break;
                    }
                case "restore":
                    {
                        string filename = context.Request.Params["backupfile"] ?? "";
                        utils.restore(filename);
                        context.Response.Write(JsonUtil.ToJson(new { success = true, msg = "恢复数据库操作成功！" }));

                        break;
                    }
            }
        }
        
    }
}